package exercise;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @classname:demo01
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/9 21:06
 * @version: 0.1
 * @since:1.8
 */
public class demo01 {
    public static void main(String[] args) {
        //构造方法一
        Date date = new Date();
        System.out.println(date);//Wed Dec 09 21:29:25 CST 2020
        System.out.println(date.getTime());//1607520623547
        //@Deprecated 注释不推荐
        //获得当前毫秒数
        long l = System.currentTimeMillis();
        System.out.println(l);//1607520785212
        //构造方法二   形参是毫秒数
        Date date1 = new Date(l);
        System.out.println(date);


        //格式化数据
        String patter ="yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sp = new SimpleDateFormat(patter);
        long l1 = System.currentTimeMillis();
        String format = sp.format(l1);
        System.out.println(format);




    }
}
